#include "linear.h"

int stack_is_empty(struct Stack* stack) {
	if (stack->first == NULL)
		return 1;
	return 0;
}

void push(struct Stack* stack, int item) {
	struct node* oldFirst = stack->first;
	stack->first = (struct node *) malloc(sizeof(struct node));
	stack->first->item = item;
	stack->first->next = oldFirst;
	(stack->n)++;
}

int pop(struct Stack* stack) {
	struct node* node = stack->first;
	int res = node->item;
	stack->first = node->next;
	free((void *) node);
	(stack->n)--;
	return res;
}

struct Stack s1;
int n1;
extern int n1;
void main2() {
	struct Stack* stack;

	stack = (struct Stack *) malloc(sizeof(struct Stack));
	stack->first = NULL;

	push(stack, 1);
	push(stack, 2);

	while(!stack_is_empty(stack)) 
		printf("size is %d, res is %d\n", stack->n, pop(stack));

	push(&s1, 1);
	push(&s1, 2);
	while (!stack_is_empty(&s1))
		printf("%d = %d\n", s1.n, pop(&s1));
	int n2;
	printf("n1 is %d, n2 is %d\n", n1, n2);
}
